// src/common/utils/path-matcher.util.ts
import { EXCLUDED_PATHS } from '@/configuration/excluded-paths.configuration';
// 组件类型
export type ComponentType = 'guard' | 'interceptor' | 'pipe';

/**
 * 路径匹配工具（纯静态方法，无需实例化）
 */
export class PathMatcher {
    /**
     * 获取指定组件的所有排除路径（全局 + 组件专属）
     */
    static getExcludedPaths(componentType: ComponentType, customPaths: string[]): string[] {
        return [
            ...EXCLUDED_PATHS.global,
            ...EXCLUDED_PATHS[componentType],
            ...customPaths,
        ];
    }

    /**
     * 检查当前路径是否需要排除
     */
    static isExcluded(currentPath: string, componentType: ComponentType, customPaths: string[] = []): boolean {
        const excludedPaths = this.getExcludedPaths(componentType, customPaths);

        return excludedPaths.some(path => {
            if (path.endsWith('*')) {
                const prefix = path.slice(0, -1);
                return currentPath.startsWith(prefix);
            }
            return currentPath === path;
        });
    }
}